<?php

/**
 * Created by PhpStorm.
 * User: Lenovo
 * Date: 2019/4/19
 * Time: 16:32
 */
class UserAction extends CheckLoginAction{
    function query(){
        $User=M('Login');
        echo $User->getFieldById(session('userId'),'money');
    }
    function cunkuan(){
        $a = M('Login');
        $input=$a->create();
        $userId=session('userId');
        $data = $a->where("id=%s",$userId)->select();
        $b=$data[0]["money"];
        $c=$input["money"];
        $r=$b+$c;
        $a->where("id=%s",$userId)->save(array("money"=>$r));
        $this->ajaxReturn(array('mss'=>"存款成功"));
    }
    function qukuan(){
        $a=M('Login');
        $input=$a->create();
        $userId=session('userId');
        $data = $a->where("id=%s",$userId)->select();
        $b=$data[0]["money"];
        $c=$input["money"];
        $r=$b-$c;
        if($r<=0){
            $this->ajaxReturn(array('mss'=>"余额不足"));
        }else{
            $a->where("id=%s",$userId)->save(array("money"=>$r));
            $this->ajaxReturn(array('mss'=>"取款成功"));
        }
    }
}